global infile "DataMain.dta"
global outfile "$results\Figure 1"


* Create means

use "$infile", clear
drop if dupindicator == 1
egen watercohort = mean(water), by(cohort week)
egen logwatercohort = mean(logwater), by(cohort week)
duplicates drop cohort week, force
sort cohort week

sum watercohort if treat == 0 & cohort == 1
gen wc1 = r(mean)
sum watercohort if treat == 1 & cohort == 1
gen wt1 = r(mean)
sum watercohort if treat == 0 & cohort == 2
gen wc2 = r(mean)
sum watercohort if treat == 1 & cohort == 2
gen wt2 = r(mean)
sum watercohort if treat == 0 & cohort == 3
gen wc3 = r(mean)
sum watercohort if treat == 1 & cohort == 3
gen wt3 = r(mean)


* Add lines

set obs `=_N + 2'
sum date if week == -26
sum date if week2 == -9
sum date if week2 == 190
replace date = 19421.9 if _n == _N - 1
replace date = 20815.1 if _n == _N
gen period1 = 55 if date >= 18993 & date <= 19422
gen period2 = 55 if date >= 19422 & date <= 20815
local period1midpoint = (18993+19422)/2
local period2midpoint = (19422+20815)/2
sort date


* Figure 1. Time-series

tw (line watercohort date if cohort == 1) ///
(line wc1 date if cohort == 1 & treat == 0, lc(dkorange) lw(thick)) ///
(line wt1 date if cohort == 1 & treat == 1, lc(dkorange) lw(thick)) ///
(area period1 date, color(gs10%70) base(40)), ///
xli(19175, lc(navy)) tlabel(, format(%dm-Y)) xti("") yti(Weekly use (mean l/day)) ///
graphregion(color(white)) ti(A. Group 1 hot water use) leg(off) ///
text(110 19350 "July 1, 2012") ///
yscale(r(40 120)) ylab(40(20)120) text(48 `period1midpoint' "Period 1") 
graph save "$results\TempA", replace

tw (line watercohort date if cohort == 2, lc(maroon) lp(dash)) ///
(line wc2 date if cohort == 2 & treat == 0, lc(dkorange) lw(thick)) ///
(line wt2 date if cohort == 2 & treat == 1, lc(dkorange) lw(thick)) ///
(area period2 date, color(gs10%70) base(40)), ///
xli(19479, lc(maroon) lp(dash)) ///
tlabel(, format(%dm-Y)) xti("") yti(Weekly use (mean l/day)) ///
graphregion(color(white)) ti(B. Group 2 hot water use) leg(off) ///
text(110 19660 "May 1, 2013") ///
yscale(r(40 120)) ylab(40(20)120) text(48 `period2midpoint' "Period 2") 
graph save "$results\TempB", replace

tw (line watercohort date if cohort == 3, lc(forest_green) lp(shortdash)) ///
(line wc3 date if cohort == 3 & treat == 0, lc(dkorange) lw(thick)) ///
(line wt3 date if cohort == 3 & treat == 1, lc(dkorange) lw(thick)) ///
(area period2 date, color(gs10%70) base(40)), ///
xli(19479, lc(maroon) lp(dash)) ///
tlabel(, format(%dm-Y)) xti("") yti(Weekly use (mean l/day)) ///
graphregion(color(white)) ti(C. Group 3 hot water use) leg(off) ///
text(90 19660 "May 1, 2013") ///
yscale(r(40 120)) ylab(40(20)120) text(48 `period2midpoint' "Period 2") 
graph save "$results\TempC", replace

graph combine "$results\TempA" "$results\TempB" "$results\TempC", ///
rows(3) xcommon ycommon graphregion(color(white)) ysize(8) iscale(0.7) 
graph save "$outfile", replace

